var openid = getQueryString("openid");

function writeCom(){
	$.ajax({
		url: API_URL+'agent/getbyopenid?openid='+ openid,
		type: 'GET',
		dataType: "JSON",
		data:'',
		async: false,
		success: function (obj){
			if(obj.status.code==0){
				var myData = obj.data[0];
				$('#entry_time').val(myData.entry_time);
				$('#regional').find("option[text='"+myData.regional+"']").attr("selected",true);
				$('#channel').find("option[text='"+myData.channel+"']").attr("selected",true);
				$('#branch').val(myData.branch); 
				$('#located_branch').val(myData.located_branch); 
				$('#department').val(myData.department); 
				$('#position').find("option[text='"+myData.position+"']").attr("selected",true);
				$('#position_time').val(myData.position_time); 
				$('#training_type').find("option[text='"+myData.training_type+"']").attr("selected",true);
				$('#number_of_periods').val(myData.number_of_periods); 
				$('#experience').find("option[text='"+myData.experience+"']").attr("selected",true);
				$('#id').val(myData.id); 
			}
			
		},
		error: function (data){
			console.log("服务器异常!");
		}
	});

   
}

function rewriteCom(){
    $.ajax({
        url: API_URL+'agent/saveorupdate',
        type: 'POST',
        dataType: "JSON",
        data:$('#rewrite_com').serialize(),
        async: false,
        success: function (obj){
            if (obj.status.code == 0) {
                window.location = 'person_mainpage.html?openid='+openid;
            }else{
                alert('服务错误');
            }
        },
        error: function (data){
            console.log("服务器异常!");
        }
    });
}
$('#save').on('click',function(){
    rewriteCom();
})